package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA
 *
 * @Date: 2022/12/23 - 10:11
 * @Author: Hyoung
 * @Description:
 */

@Api(tags = "医院接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class AdminHospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{page}/{limit}")
    public R pageList(@PathVariable("page") @ApiParam(value = "页码") Integer page,
                      @PathVariable("limit") @ApiParam(value = "每页数量") Integer limit,
                      @ApiParam(value = "查询字符串")
                      String hosname) {

        Page<Hospital> pageModel = hospitalService.selectPage(page, limit, hosname);

        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation(value = "更新上线状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public R lock(
            @PathVariable("id") String id,
            @PathVariable("status") Integer status) {

        if (status != 0 && status != 1) {
            return R.error().message("非法的状态值");
        }
        hospitalService.updateStatus(id, status);
        return R.ok();
    }

    @ApiOperation(value = "获取医院详情")
    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") String id) {
        Hospital hospital = hospitalService.show(id);
        return R.ok().data("hospital", hospital);
    }
}
